package rules

// FieldRule 定义字段过滤规则，包括包含和排除的字段列表
type FieldRule struct {
	Include []string `yaml:"include" toml:"include" env:"FIELDRULE_INCLUDE"` // 包含的字段路径
	Exclude []string `yaml:"exclude" toml:"exclude" env:"FIELDRULE_EXCLUDE"` // 排除的字段路径
}

// Config 定义全局配置，包含各资源类型的字段过滤规则
type Config struct {
	Deployment  *FieldRule `yaml:"deployment" toml:"deployment" env:"CONFIG_DEPLOYMENT"` // Deployment资源过滤规则
	DaemonSet   *FieldRule `yaml:"daemonset" toml:"daemonset" env:"CONFIG_DAEMONSET"`
	StatefulSet *FieldRule `yaml:"statefulset" toml:"statefulset" env:"CONFIG_STATEFULSET"`
	Job         *FieldRule `yaml:"job" toml:"job" env:"CONFIG_JOB"`
	CronJob     *FieldRule `yaml:"cronjob" toml:"cronjob" env:"CONFIG_CRONJOB"`

	Service   *FieldRule `yaml:"service" toml:"service" env:"CONFIG_SERVICE"`       // Service资源过滤规则
	ConfigMap *FieldRule `yaml:"configmap" toml:"configmap" env:"CONFIG_CONFIGMAP"` // ConfigMap资源过滤规则
	Secret    *FieldRule `yaml:"secret" toml:"secret" env:"CONFIG_SECRET"`          // Secret资源过滤规则

	ServiceAccount      *FieldRule `yaml:"serviceaccount" toml:"serviceaccount" env:"CONFIG_SERVICEACCOUNT"`                // ServiceAccount资源过滤规则
	Role                *FieldRule `yaml:"role" toml:"role" env:"CONFIG_ROLE"`                                              // Role资源过滤规则
	RoleBindings        *FieldRule `yaml:"rolebindings" toml:"rolebindings" env:"CONFIG_ROLEBINDINGS"`                      // RoleBindings资源过滤规则
	ClusterRole         *FieldRule `yaml:"clusterrole" toml:"clusterrole" env:"CONFIG_CLUSTERROLE"`                         // ClusterRole资源过滤规则
	ClusterRoleBindings *FieldRule `yaml:"clusterrolebindings" toml:"clusterrolebindings" env:"CONFIG_CLUSTERROLEBINDINGS"` // ClusterRoleBindings资源过滤规则

	PV  *FieldRule `yaml:"pv" toml:"pv" env:"CONFIG_PV"`
	PVC *FieldRule `yaml:"pvc" toml:"pvc" env:"CONFIG_PVC"`
}

type Rules struct {
	*Config `yaml:"config" toml:"config" env:"RULES_CONFIG"`
}

func NewDefaultRules() *Rules {
	//dep := &FieldRule{
	//	Include: nil,
	//	Exclude: nil,
	//}
	dep := &FieldRule{
		Include: []string{
			//"metadata/labels/app",
			//"metadata/labels/io.tencent.bcs.clusterid",
			//"spec/template/metadata/labels/a",
			//"spec/template/metadata/labels/app",
			//"spec/template/metadata/labels/b",
			//"spec/template/metadata/labels/io.tencent.bcs.clusterid",

			//"spec/template/spec/containers/terminationMessagePath",
			//"spec/template/spec/containers/terminationMessagePolicy",
			//"spec/template/spec/containers/env",
			//"spec/template/spec/restartPolicy",
			//"spec/template/spec/terminationGracePeriodSeconds",
			//"spec/template/spec/dnsPolicy",
			//"spec/template/spec/securityContext",
			//"spec/template/spec/schedulerName",
		},
		Exclude: []string{
			"metadata/managedFields",
			"metadata/creationTimestamp",
			"metadata/generation",
			"metadata/resourceVersion",
			"metadata/uid",
			"spec/progressDeadlineSeconds",
			"spec/revisionHistoryLimit",
			"spec/strategy",
			"spec/template/metadata/creationTimestamp",
			"spec/template/spec/terminationGracePeriodSeconds",
			"spec/template/spec/containers/terminationMessagePath",
			"spec/template/spec/containers/terminationMessagePolicy",
			"spec/template/spec/initContainers/terminationMessagePath",
			"spec/template/spec/initContainers/terminationMessagePolicy",
			"spec/template/spec/dnsPolicy",
			"spec/template/spec/terminationGracePeriodSeconds",
			"spec/template/spec/securityContext",
			"spec/template/spec/schedulerName",
			"status",
		},
	}
	statefulset := &FieldRule{
		Include: []string{},
		Exclude: []string{
			"metadata/annotations",
			"metadata/creationTimestamp",
			"metadata/generation",
			"metadata/managedFields",
			"metadata/resourceVersion",
			"metadata/uid",
			"spec/revisionHistoryLimit",
			"spec/strategy",
			"spec/template/metadata/creationTimestamp",
			"spec/template/metadata/annotations",
			"spec/template/spec/containers/terminationMessagePath",
			"spec/template/spec/containers/terminationMessagePolicy",
			"spec/template/spec/initContainers/terminationMessagePath",
			"spec/template/spec/initContainers/terminationMessagePolicy",
			"spec/template/spec/dnsPolicy",
			"spec/template/spec/terminationGracePeriodSeconds",
			"spec/template/spec/securityContext",
			"spec/template/spec/schedulerName",
			"spec/template/spec/restartPolicy",
			"status",
		},
	}
	daemonset := &FieldRule{
		Include: []string{},
		Exclude: []string{
			"metadata/annotations",
			"metadata/creationTimestamp",
			"metadata/generation",
			"metadata/managedFields",
			"metadata/resourceVersion",
			"metadata/uid",
			"spec/revisionHistoryLimit",
			"spec/strategy",
			"spec/template/metadata/creationTimestamp",
			"spec/template/metadata/annotations",
			"spec/template/spec/containers/terminationMessagePath",
			"spec/template/spec/containers/terminationMessagePolicy",
			"spec/template/spec/initContainers/terminationMessagePath",
			"spec/template/spec/initContainers/terminationMessagePolicy",
			"spec/template/spec/dnsPolicy",
			"spec/template/spec/terminationGracePeriodSeconds",
			"spec/template/spec/securityContext",
			"spec/template/spec/schedulerName",
			"spec/template/spec/restartPolicy",
			"status",
		},
	}
	job := &FieldRule{
		Include: []string{},
		Exclude: []string{
			"metadata/annotations",
			"metadata/creationTimestamp",
			"metadata/generation",
			"metadata/managedFields",
			"metadata/resourceVersion",
			"metadata/selfLink",
			"metadata/uid",
			"spec/backoffLimit",
			"spec/completions",
			"spec/completions",
			"spec/template/metadata/creationTimestamp",
			"spec/template/metadata/annotations",
			"spec/template/spec/containers/terminationMessagePath",
			"spec/template/spec/containers/terminationMessagePolicy",
			"spec/template/spec/terminationGracePeriodSeconds",
			"spec/template/spec/securityContext",
			"spec/template/spec/schedulerName",
			"spec/template/spec/restartPolicy",
			"status",
		},
	}
	cronjob := &FieldRule{
		Include: []string{},
		Exclude: []string{
			"metadata/annotations",
			"metadata/creationTimestamp",
			"metadata/managedFields",
			"metadata/resourceVersion",
			"metadata/uid",
			"metadata/selfLink",
			"spec/concurrencyPolicy",
			"spec/jobTemplate/metadata/creationTimestamp",
			"spec/jobTemplate/spec/template/metadata/creationTimestamp",
			"spec/jobTemplate/metadata/annotations",
			"spec/jobTemplate/spec/template/spec/containers/terminationMessagePath",
			"spec/jobTemplate/spec/template/spec/containers/terminationMessagePolicy",
			"spec/jobTemplate/spec/template/spec/dnsPolicy",
			"spec/jobTemplate/spec/template/spec/terminationGracePeriodSeconds",
			"spec/jobTemplate/spec/template/spec/securityContext",
			"spec/jobTemplate/spec/template/spec/schedulerName",
			"spec/successfulJobsHistoryLimit",
			"spec/suspend",
			"status",
		},
	}
	ser := &FieldRule{
		Include: []string{
			//"metadata/labels/io.tencent.bcs.clusterid",
			//"metadata/labels/io.tencent.bcs.controller.name",
			//"metadata/labels/io.tencent.bcs.controller.type",
		},
		Exclude: []string{
			"metadata/creationTimestamp",
			"metadata/managedFields",
			"metadata/resourceVersion",
			"metadata/uid",
			"status",
			"spec/clusterIP",
			"spec/clusterIPs",
			"spec/internalTrafficPolicy",
			"spec/ipFamilies",
			"spec/ipFamilyPolicy",
			"spec/externalTrafficPolicy",
		},
	}
	cfg := &FieldRule{
		Include: []string{
			"apiVersion",
			"kind",
			"metadata/name",
			"metadata/namespace",
			"metadata/labels",
			"data",
		},
	}
	secret := &FieldRule{
		Include: []string{
			"apiVersion",
			"kind",
			"metadata/name",
			"metadata/namespace",
			"data",
			"type",
		},
	}
	sa := &FieldRule{
		Include: []string{
			"apiVersion",
			"kind",
			"metadata/name",
			"metadata/namespace",
		},
	}
	role := &FieldRule{
		Include: []string{
			"apiVersion",
			"kind",
			"metadata/name",
			"metadata/namespace",
			"rules",
		},
	}
	roleBindings := &FieldRule{
		Include: []string{
			"apiVersion",
			"kind",
			"metadata/name",
			"metadata/namespace",
			"subjects",
			"roleRef",
		},
	}
	clusterRole := &FieldRule{
		Include: []string{
			"apiVersion",
			"kind",
			"metadata/name",
			"rules",
		},
	}
	clusterRoleBindings := &FieldRule{
		Include: []string{
			"apiVersion",
			"kind",
			"metadata/name",
			"subjects",
			"roleRef",
		},
	}
	pv := &FieldRule{
		Exclude: []string{
			"metadata/annotations",
			"metadata/finalizers",
			"metadata/creationTimestamp",
			"metadata/managedFields",
			"metadata/resourceVersion",
			"metadata/uid",
			"spec/claimRef/kind",
			"spec/claimRef/uid",
			"spec/claimRef/apiVersion",
			"spec/claimRef/resourceVersion",
			"status",
		},
	}
	pvc := &FieldRule{
		Exclude: []string{
			"metadata/annotations",
			"metadata/finalizers",
			"metadata/creationTimestamp",
			"metadata/managedFields",
			"metadata/resourceVersion",
			"metadata/uid",
			"status",
		},
	}
	return &Rules{
		Config: &Config{
			Deployment:          dep,
			StatefulSet:         statefulset,
			DaemonSet:           daemonset,
			Job:                 job,
			CronJob:             cronjob,
			Service:             ser,
			ConfigMap:           cfg,
			Secret:              secret,
			ServiceAccount:      sa,
			Role:                role,
			RoleBindings:        roleBindings,
			ClusterRole:         clusterRole,
			ClusterRoleBindings: clusterRoleBindings,
			PV:                  pv,
			PVC:                 pvc,
		},
	}
}
